package net.suncapper.wcss.common.utls;


import jakarta.servlet.http.HttpSession;
import net.suncapper.wcss.model.domain.WhitelistSetting;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;



public class SessionUtils {
    private static final String USERKEY = "sessionUser";

    public static HttpSession session() {
        ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        return attr.getRequest().getSession(true); // true == allow create
    }


    public static void setCurrentLoginUser(WhitelistSetting user) {
        session().setAttribute(USERKEY, user);
    }
    public static WhitelistSetting getCurrentLoginUser()
    {
        return (WhitelistSetting) session().getAttribute(USERKEY);
    }

    public static boolean clearLoginUser() {
        session().removeAttribute(USERKEY);
        return true;
    }
}
